'use strict';
const Service = require('egg').Service;
class ShopService extends Service {

 
  // 获取申请开店列表
  async getApplyShop(payload) {
    const { app } = this;
    const Op = app.Sequelize.Op;
    const { pageNum, pageSize, name, user_id, status, phone, begin_pubdate, idCard, end_pubdate } = payload;
    const where = {};
    if (name) { where.name = name; }
    if (user_id) { where.user_id = user_id; }
    if (status) { where.status = status; }
    if (phone) { where.phone = phone; }
    if (idCard) { where.idCard = idCard; }
    if (begin_pubdate && end_pubdate) {
      where.createdAt = { [Op.between]: [ begin_pubdate, end_pubdate ] };
    }// 查询这个字段-xx之间  }
    // notBetween
    const { count, rows } = await app.model.MallShopApply.findAndCountAll({
      where,
      order: [[ 'createdAt', 'desc' ]], // 根据创建时间倒序排序
      offset: (pageNum - 1) * pageSize,
      limit: pageSize * 1,
    });
    return {
      pageNum,
      pageSize,
      total: count,
      list: rows,
    };
  }

  // 根据id获取申请开店详细信息
  async findByPk(id) {
    return await this.app.model.MallShopApply.findByPk(id);
  }

  // 审核申请开店信息
  async auditApplyShop(id, payload) {
    const { app } = this;
    const { status, desc } = payload;
    console.log({ status, desc });
    return await app.model.MallShopApply.update({ status, desc }, { where: { id } });
  }


}

module.exports = ShopService;
